package com.sdgakj.web.h5;

import com.google.common.collect.Maps;
import com.sdgakj.dto.base.ResCode;
import com.sdgakj.dto.base.ResResult;
import com.sdgakj.entity.Feedback;
import com.sdgakj.rest.UserLoginRestController;
import com.sdgakj.service.ServiceException;
import com.sdgakj.service.feedback.FeedbackService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springside.modules.web.MediaTypes;

import java.util.Map;


@RestController
@RequestMapping(value = "/h5/feedback")
public class H5FeedbackController {
	
	private static final String PAGE_SIZE = "10";
	
	private static Map<String,String> sortTypes =Maps.newLinkedHashMap();
	private static Logger logger = LoggerFactory.getLogger(H5FeedbackController.class);

	@Autowired
	private FeedbackService feedbackService;

	static {
		sortTypes.put("auto", "自动");
	}

    /**
     * 意见反馈提交
     * @return
     */
    @RequestMapping(value="/send",method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
	public ResResult send(@RequestParam(value = "userId", required = false) Long userId,
								  @RequestParam(value = "message", required = false) String message,
								  @RequestParam(value = "mobile", required = false) String mobile) {
		ResResult result = new ResResult();

		Feedback feedback = new Feedback();
		feedback.setUserId(1L);
		feedback.setMessage(message);
		feedback.setMobile(mobile);

		try {
			feedbackService.saveFeedback(feedback);
		} catch (ServiceException e) {
			result.setResCode(e.getResCode());
			logger.info("I-[创建意见反馈]业务错误", e);
		} catch (Exception e) {
			result.setResCode(ResCode.ERROR);
			logger.error("I-[创建意见反馈]程序异常", e);
		}
		return result;

    }

}
